import { delay } from 'roadhog-api-doc';

function getFakeList(req, res) {
  const json = { code: 200, success: true, msg: '操作成功' };
  let data = [];
  const fakeList = [
    {
      id: '1',
      title: 'MOCK DATA 测试标题1',
      content: '测试内容1',
      data: '2020-05-09 12:00:00',
    },
    {
      id: '2',
      title: 'MOCK DATA 测试标2',
      content: '测试内容2',
      data: '2020-04-09 12:00:00',
    },
    {
      id: '3',
      title: 'MOCK DATA 测试标题3',
      content: '测试内容3',
      data: '2020-03-09 12:00:00',
    }
  ];

  if (req.query.title) {
    data = fakeList.filter(item => { return item.title.includes(req.query.title) });
  } else {
    data = fakeList;
  }

  json.data = {
    total: 3,
    size: 10,
    current: 1,
    searchCount: true,
    pages: 10,
    records: data,
  };
  return res.json(json);
}

function getFakeDetail(req, res) {
  const json = { code: 200, success: true, msg: '操作成功' };
  json.data = {
    id: '1',
    clientId: 'sword',
    clientSecret: 'sword_secret',
    scope: 'all',
    authorizedGrantTypes: 'refresh_token,password,authorization_code',
    webServerRedirectUri: 'https://sword.bladex.vip',
    accessTokenValidity: '3600',
    refreshTokenValidity: '36000',
  };
  return res.json(json);
}

function fakeSuccess(req, res) {
  const json = { code: 200, success: true, msg: '操作成功' };
  return res.json(json);
}

const proxy = {
  'GET /api/demo/list': getFakeList,
  'GET /api/demo/detail': getFakeDetail,
};
export default delay(proxy, 1000);
